<?php
require_once("report.php");
class Detailed_bvpoints extends Report
{
	function __construct()
	{
		parent::__construct();
	}
	
	public function getDataColumns()
	{
		return array(
			'summary' => array(
				array('data'=>'Sales ID', 'align'=> 'left'), 
				array('data'=>'GNMember ID', 'align'=> 'left'), 
				array('data'=>'Customer', 'align'=> 'left'), 
				array('data'=>'Date', 'align'=> 'left'), 
				array('data'=>'BV/Item', 'align'=> 'left'), 
				array('data'=>'Product', 'align'=> 'left'), 
				array('data'=>'Quantity', 'align'=> 'left'), 
				array('data'=>'BV Points', 'align'=> 'left')
			)
		);


	}
	
	public function getData()
	{
		/*
		$this->db->select('sale_id, sale_time, sale_date, sum(quantity_purchased) as items_purchased, CONCAT(employee.first_name," ",employee.last_name) as employee_name, CONCAT(customer.first_name," ",customer.last_name) as customer_name, sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax, sum(profit) as profit, payment_type, comment', false);
		$this->db->from('sales_items_temp');
		$this->db->join('people as employee', 'sales_items_temp.employee_id = employee.person_id');
		$this->db->join('people as customer', 'sales_items_temp.customer_id = customer.person_id', 'left');

		$this->db->where('deleted', 0);
		$this->db->where('customer_id', $this->params['customer_id']);
		$this->db->like('payment_type', lang('sales_giftcard'));
		$this->db->group_by('sale_id');
		$this->db->order_by('sale_date');

		$data = array();
		$data['summary'] = $this->db->get()->result_array();
		$data['details'] = array();
		foreach($data['summary'] as $key=>$value)
		{
			$this->db->select('item_number, item_kit_number, items.name as item_name, item_kits.name as item_kit_name, sales_items_temp.category, quantity_purchased, serialnumber, sales_items_temp.description, subtotal,total, tax, profit, discount_percent');
			$this->db->from('sales_items_temp');
			$this->db->join('items', 'sales_items_temp.item_id = items.item_id', 'left');
			$this->db->join('item_kits', 'sales_items_temp.item_kit_id = item_kits.item_kit_id', 'left');
			$this->db->where('sale_id = '.$value['sale_id']);
			$data['details'][$key] = $this->db->get()->result_array();
		}
		
		return $data;*/


		$this->db->select('sale.sale_id, pep.gnmember_id, pep.first_name , pep.last_name, sale.sale_time as `Date`, item.bv_points as `BVITEM`, item.name as `Product`, saleitem.quantity_purchased as `Quantity`, (item.bv_points * saleitem.`quantity_purchased`) as `BV Points`');
		$this->db->from('people as pep');
		$this->db->join('sales as sale', 'pep.person_id = sale.customer_id');
		$this->db->join('sales_items as saleitem', 'sale.sale_id = saleitem.sale_id');
		$this->db->join('items as item', 'item.item_id = saleitem.item_id');

		$this->db->where('sale.sale_time >=', $this->params['start_date']);
		$this->db->where('sale.sale_time <=', $this->params['end_date']);
		$this->db->where('pep.gnmember_id != ', 0);

		$data = array();
		$data['summary'] = $this->db->get()->result_array();
		$data['details'] = array();

		return $data;
	}
	
	public function getSummaryData()
	{
		/*
		$this->db->select('sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax, sum(profit) as profit');
		$this->db->from('sales_items_temp');
		$this->db->where('deleted', 0);
		$this->db->where('customer_id', $this->params['customer_id']);
		$this->db->like('payment_type', lang('sales_giftcard'));
		return $this->db->get()->row_array();*/
	}
}?>